<?php
namespace Modules\Code\Http\Controllers\Admin\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use Modules\Code\Entities\CodeRecord;

use Validator;
use ThrowException;
use Auth;

class CodeRecordController extends Controller
{
    public function index(Request $req)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $options = $req->all();

        // $options['order_by'] = ['list_weight' => 'desc'];
        $options['with'] = ['user', 'code'];

        $options['builder'] = CodeRecord::whereHas('code');

        $list = CodeRecord::getList($options);

        return $list->generateListResponse();
    }

    public function show(Request $req, $uuid)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $item = CodeRecord::getEntity([
            'uuid' => $uuid
        ]);

        $info = $item->getInfo();

        return [
            'info' => $info
        ];
    }

    // public function destroy(Request $req, $uuid)
    // {
    //     $rule = [
    //     ];
    //     Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

    //     $item = CodeRecord::getEntity([
    //         'uuid' => $uuid
    //     ]);

    //     $item->delete();

    //     return [];
    // }
}
